1 from .other import dict_to_csv_line
2
3 keys = (
'id', 'name', 'price', 'quantity',
4         
'season', 'type', 'sub_type', 'description')
5
6
7 def get_products():
8     data = []
9     file = open(
'products.csv')
10
11   # search = input(
'ID or name of the product?: ')
12     
for line in file:
13         spacing = line.split(
',')
14         product = {
15             
"id": int(spacing[0]),
16             
"name": spacing[1],
17             
"price": float(spacing[2]),
18             
"quantity": int(spacing[3]),
19             
"season": spacing[4],
20             
"type": spacing[5],
21             
"sub_type": spacing[6],
22             
"description": spacing[7].replace('\n', '')
23         }
24         data.append(product)
25
26     file.close()
27     
return data
28
29
30 def update_products(product_list):
31     file = open(
'products.csv', 'w')
32     
for p in product_list:
33         line = dict_to_csv_line(p, keys)
34         file.write(line)
35
36     file.close()


Gõ tìm kiếm nhanh...